import { request } from 'umi';

/**
 * 查询用户
 */
export const userInfo = (
  server: string,
  params: {
    page: number;
    size: number;
    [key: string]: any;
  },
) => {
  return request<any>(`${server}/user`, {
    params,
    getResponse: true,
  });
};

/**
 * 添加用户
 */
export const addUser = (server: string, user: any) => {
  return request<any>(`${server}/user`, {
    method: 'post',
    getResponse: true,
    data: user,
  });
};

/**
 * 用户登陆
 */
export const login = (server: string, user: any) => {
  // return request<any>(`${server}/login`, {
  return request<any>(`${server}/api/peerUser/webLogin`, {
    method: 'post',
    getResponse: true,
    data: user,
  });
};
/**
 * 修改用户
 */
export const updateUser = (server: string, user: any) => {
  return request<any>(`${server}/api/peerUser/updateUserInfo`, {
    method: 'post',
    getResponse: true,
    data: user,
  });
};
/**
 * 修改密码
 */
export const updatePassword = (server: string, user: any) => {
  return request<any>(`${server}/api/peerUser/updatePassword`, {
    method: 'post',
    getResponse: true,
    data: user,
  });
};
/**
 * 删除用户
 */
export const deleteUser = (server: string, id: any) => {
  return request<any>(`${server}/user`, {
    method: 'delete',
    getResponse: true,
    params: { id },
  });
};
/**
 * 修改用户登录状态
 */
export const updateLoginStatus = (
  server: string,
  loginStatus: number,
  id: any,
) => {
  return request<any>(`${server}/api/peerUser/updateLoginStatus`, {
    method: 'post',
    getResponse: true,
    data: { id, loginStatus },
  });
};


/**
 * 查询用户
 */
export const userList = (server: string) => {
  return request<any>(`${server}/api/peerUser/userList`, {
    getResponse: true,
  });
};
